package com.example.swagger.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Profile({"dev","test"})
@Configuration
@EnableSwagger2
public class Swagger2 {

    /**
     * swagger2的配置文件，这里可以配置swagger2
     * 的一些基本的内容，比如扫描的包等等
     *
     * @return
     */
    @Bean
    public Docket createResApi(){

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.swagger"))
                .build();
    }

    /**
     * swagger 文档详细介绍
     *
     * @return
     */
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("swagger示例")
                .contact(new Contact("Jingwei","http://127.0.0.1","836075480@qq.com"))
                .version("1.0")
                .description("swagger示例项目")
                .build();
    }
}
